package viv.karaoke.book;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class SongAdapter extends BaseAdapter {

	private Context mContext;
	private List<song> mItems;
	
	public SongAdapter(Context c, List<song> items) {
		mContext = c;
		mItems = items;
	}
	
	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public Object getItem(int position) {
		return mItems.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		View aView = inflater.inflate( R.layout.activity_song, null );
		
		ImageView favouriteId = (ImageView)aView.findViewById(R.id.bookmark);
		TextView songId = (TextView)aView.findViewById(R.id.number);
		TextView name = (TextView)aView.findViewById(R.id.name);
		TextView artist = (TextView)aView.findViewById(R.id.artist);
		
		songId.setText(String.valueOf(mItems.get(position).getSongId()));
		name.setText(mItems.get(position).getSongName());
		artist.setText(mItems.get(position).getArtist());

		boolean bookMark = mItems.get(position).getBookmark();
		if(bookMark)
		{
			favouriteId.setVisibility(View.VISIBLE);
			favouriteId.setImageResource(android.R.drawable.star_on);
		}
		else
		{
//			favouriteId.setVisibility(View.INVISIBLE);
			favouriteId.setImageResource(android.R.drawable.star_off);
		}
		return aView;
	}
	
	public void add(song aSong)
	{
		mItems.add(aSong);
	}
	public void update(song aSong, int pos)
	{
		mItems.set(pos, aSong);
	}
	
	
	public void clear()
	{
		mItems.clear();
	}
}
